package com.credithc.customers.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.TypeReference;
import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.customers.api.service.ICustomerUnifyService;
import com.credithc.customers.api.utils.RequestUtils;
import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.ro.*;
import com.credithc.customers.base.utils.CustomerUtils;
import com.credithc.framework.log.annotation.Trace;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: 统一登录相关接口
 * @Author: Denghx
 * @Date: 2020/1/13 15:55
 * @Description: com.credithc.customers.api.controller
 * @Version: V1.0.0
 */
@RestController
@RequestMapping("/api/yzt/v1/unify")
@Slf4j
@Trace
public class CustomerUnifyController {
    @Autowired
    MessageFactory messageFactory;
    @Autowired
    ICustomerUnifyService customerUnifyService;
    @Autowired
    RequestUtils requestUtils;

    /**
     * @description: 忘记、修改密码接口
     * @author: denghx
     * @date: 2021/2/18 14:18
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/forgetPwd")
    public Message forgetPwd(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyPwdRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyPwdRo>>() {
            });
            String sourceType = bRequest.getBody().getSourceType();
            if (StringUtils.isNotBlank(sourceType) && sourceType.equals("1")) {
            } else {
                requestUtils.checkRequestBaseParam(requestStr);
            }
            customerUnifyService.forgetPwd(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-修改密码】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 统一注册接口
     * @author: fby
     * @date: 2020/1/14 14:14
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/register")
    public Message register(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyRegisterRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyRegisterRo>>() {
            });
            //requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.unifyRegister(bRequest);
            if (map.get("msg") != null) {
                return messageFactory.getInstance(Integer.parseInt(map.get("code").toString()), map.get("msg").toString(), map.get("resMap"));
            }
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map.get("resMap"));
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-注册】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 统一登录接口
     * @author: fby
     * @date: 2020/01/15 10:12
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/login")
    public Message login(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyLoginRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyLoginRo>>() {
            });
//            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.login(bRequest);
            if (map.get("msg") != null) {
                return messageFactory.getInstance(Integer.parseInt(map.get("code").toString()), map.get("msg").toString(), map.get("resMap"));
            }
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "登录成功", map.get("resMap"));
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【登录】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 注册且登陆接口
     * @author: fby
     * @date: 2020/01/17 09:49
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/registerLogin")
    public Message unifyRegisterLogin(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyRegisterLoginRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyRegisterLoginRo>>() {
            });
//            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.unifyRegisterLogin(bRequest);
            if (map.get("msg") != null) {
                return messageFactory.getInstance(Integer.parseInt(map.get("code").toString()), map.get("msg").toString(), map.get("resMap"));
            }
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map.get("resMap"));
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【注册/登录】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 生成商户登录账号
     * @author: fby
     * @date: 2020/4/23 14:22
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/getBusinessUser")
    @Trace
    public Message getBusinessUser(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerInfoRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerInfoRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, String> map = customerUnifyService.getBusinessUser(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【生成商户端登录账号】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/sendSmsCode")
    public Message sendSmsCode(HttpServletRequest request) {
        try {
            String ip = CustomerUtils.getIp2(request);
            CustomerUtils.checkIp(ip);
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifySmsCodeRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifySmsCodeRo>>() {
            });
            bRequest.getBody().setIp(ip);
//            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.sendSmsCode(bRequest);
            if (map.get("msg") != null) {
                return messageFactory.getInstance(Integer.parseInt(map.get("code").toString()), map.get("msg").toString(), map.get("resMap"));
            }
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map.get("resMap"));
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-发送验证码】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 用户注销接口
     * @author: denghx
     * @date: 2020/3/7 15:11
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/cancel")
    public Message cancel(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyCancelRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyCancelRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.cancel(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-注销】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 修改手机号
     * @author: denghx
     * @date: 2020/6/7 15:11
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/modifyPhone")
    public Message modifyPhone(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyModifyPhoneRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyModifyPhoneRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.modifyPhone(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-修改手机号】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 用户身份信息变更
     * @author: fby
     * @date: 2020/1/20 10:39
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/changeInfo")
    public Message changeInfo(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyUpdateRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyUpdateRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.changeInfo(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-用户身份信息变更】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 用户身份信息解绑
     * @author: fby
     * @date: 2020/1/20 15:25
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/untie")
    public Message untie(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyUntieRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyUntieRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.untie(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-解绑】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: code获取token信息接口
     * @author: denghx
     * @date: 2020/2/27 17:37
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/getToken")
    public Message getToken(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyTokenRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyTokenRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.getToken(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【code获取token信息】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 授权页面请求一账通
     * @author: denghx
     * @date: 2020/2/27 20:14
     * @param: ro
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping(value = "/grantAuth")
    public Message getGrantAuth(@RequestBody UnifyGrantAuthRo ro) {
        Map<String, Object> map = customerUnifyService.grantAuth(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    /**
     * @description: 用户点击授信后，去一账通授信
     * @author: denghx
     * @date: 2020/2/27 20:14
     * @param: ro
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping(value = "/subGrantAuth")
    public Message getSubGrantAuth(@RequestBody UnifySubGrantAuthRo ro) {
        Map<String, Object> map = customerUnifyService.subGrantAuth(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    /**
     * @description: accessToken获取用户信息
     * @author: denghx
     * @date: 2020/2/28 12:17
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/getInfoByToken")
    public Message getInfoByToken(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyTokenInfoRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyTokenInfoRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.getInfoByToken(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【token获取用户信息】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping(value = "/graphicVerify")
    public Message graphicVerify(@RequestBody UnifygraphicRo ro) {
        Map<String, Object> map = customerUnifyService.graphicVerify(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    @PostMapping(value = "/refreshGraphic")
    public Message refreshGraphic(@RequestBody UnifyRefreshGraphicRo ro) {
        Map<String, Object> map = customerUnifyService.refreshGraphic(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    @PostMapping("/queryCustInfo")
    public Message queryCustInfo(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyQueryInfoRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyQueryInfoRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.queryCustInfo(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【支付中台-客户信息查询】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @GetMapping("/healthCheck")
    public Message healthCheck() {
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "检测成功");
    }

    /**
     * @description: 依据临时code+客户号换取正式code
     * @author: denghx
     * @date: 2020/4/28 22:33
     * @param: ro
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping(value = "/getFormalCode")
    public Message getFormalCode(@RequestBody UnifyFormalCodeRo ro) {
        Map<String, Object> map = customerUnifyService.getFormalCode(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    /**
     * @description: 查询用户是否已注册接口
     * @author: fby
     * @date: 2020/5/8 14:10
     * @param: ro
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping(value = "/verifyRegister")
    public Message verifyRegister(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyVerifyRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyVerifyRo>>() {
            });
            //requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.verifyRegister(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【查询用户是否注册】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @GetMapping("/getIp")
    public Message getIp(HttpServletRequest request) {
        String ip = CustomerUtils.getIp2(request);
        Map<String, Object> map = new HashMap<>();
        map.put("ip", ip);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    @PostMapping("/verifyCode")
    public Message verifyCode(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyCodeRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyCodeRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.verifyCode(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【校验code是否失效】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/modifyBusinessInfo")
    public Message modifyBusinessInfo(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyModifyBusinessRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyModifyBusinessRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.modifyBusinessInfo(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【修改商户客户信息】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/queryBusinessModify")
    public Message queryBusinessModify(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyQueryInfoRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyQueryInfoRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.queryBusinessModify(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【查询商户修改信息】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 用户获取邀请码
     * @author: denghx
     * @date: 2020/9/3 13:53
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/getInvitationInfo")
    @Trace
    public Message getInvitationInfo(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerInvitationRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerInvitationRo>>() {
            });
            requestUtils.checkRequestBaseParam(requestStr);
            Map<String, Object> map = customerUnifyService.getInvitationInfo(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【用户获取邀请码】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/fixCustNo")
    public Message fixCustNo(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<CustomerUnifyFixRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<CustomerUnifyFixRo>>() {
            });
//            requestUtils.checkRequestBaseParam(requestStr);
            customerUnifyService.fixCustNo(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.error("【客户信息修复】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/sendSms")
    public Message sendSms(HttpServletRequest request) {
        try {
            String ip = CustomerUtils.getIp2(request);
            CustomerUtils.checkIp(ip);
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifySmsPwdRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifySmsPwdRo>>() {
            });
            bRequest.getBody().setIp(ip);
            Map<String, Object> map = customerUnifyService.sendSms(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-发送验证码】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/verifySms")
    public Message verifySms(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<VerifySmsCodeRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<VerifySmsCodeRo>>() {
            });
            customerUnifyService.verifySms(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一登录-校验验证码】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    /**
     * @description: 直接授权接口
     * @author: denghx
     * @date: 2021/5/26 10:13
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @PostMapping("/auth")
    public Message auth(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyAuthRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyAuthRo>>() {
            });
            String sourceType = bRequest.getBody().getSourceType();
            if (StringUtils.isNotBlank(sourceType) && sourceType.equals("1")) {
            } else {
                requestUtils.checkRequestBaseParam(requestStr);
            }
            Map<String, Object> map = customerUnifyService.auth(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一授权】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }

    @PostMapping("/checkAuth")
    public Message checkAuth(HttpServletRequest request) {
        try {
            String requestStr = RequestUtils.generateRequest(request);
            BaseRequest<UnifyAuthRo> bRequest = JSON.parseObject(requestStr, new TypeReference<BaseRequest<UnifyAuthRo>>() {
            });
            String sourceType = bRequest.getBody().getSourceType();
            if (StringUtils.isNotBlank(sourceType) && sourceType.equals("1")) {
            } else {
                requestUtils.checkRequestBaseParam(requestStr);
            }
            Map<String, Object> map = customerUnifyService.checkAuth(bRequest);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        } catch (IOException e) {
            throw new CustomerException(CustomerCodes.READ_REQUEST_ERROR);
        } catch (JSONException e) {
            log.info("【统一授权状态查询】接口参数格式错误，异常信息：{}", e.getMessage());
            throw new CustomerException(CustomerCodes.FAST_JSON_ERROR);
        }
    }
}
